package com.itheima.dubbo.web.controller;

import com.itheima.dubbo.UserInterface;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @DubboReference(version = "2.0.0",timeout = 5000)
    UserInterface userInterface;

    @GetMapping("findOne/{id}")
    public User findOne(@PathVariable("id") Long id) {
        boolean consumerSide = RpcContext.getContext().isConsumerSide();
        System.out.println(consumerSide);
//        URL url = RpcContext.getContext().getUrl();
//        String application = url.getParameter("application");
//        RpcContext.getContext().setAttachment("company", "itheima");
        return userInterface.findOne(id);
    }
    @GetMapping("hello")
    public String sayHello(String username) {

        return userInterface.sayHello(username);
    }


}
